package lew.bing.exp.collection;

import java.util.ListIterator;

/**
 * Created by 刘国兵 on 2018/9/1.
 */
public abstract class TransferIterator<T,R> implements ListIterator<T> {

    private ListIterator<R> from;

    public TransferIterator(ListIterator<R> from) {
        this.from = from;
    }

    @Override
    public boolean hasNext() {
        return from.hasNext();
    }

    @Override
    public T next() {
        return transfer(from.next());
    }

    @Override
    public boolean hasPrevious() {
        return from.hasPrevious();
    }

    @Override
    public T previous() {
        return transfer(from.previous());
    }

    @Override
    public int nextIndex() {
        return from.nextIndex();
    }

    @Override
    public int previousIndex() {
        return from.previousIndex();
    }

    @Override
    public void remove() {
        from.remove();
    }

    @Override
    public void set(T t) {
        throw new UnsupportedOperationException("不支持该操作");
    }

    @Override
    public void add(T t) {
        throw new UnsupportedOperationException("不支持该操作");
    }

    protected abstract T transfer(R r);

}
